<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="../layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../dtree/dtree.css" media="all">
  <link rel="stylesheet" href="../dtree/font/iconfont.css" media="all">
  <style>

</style>
</head>
<body>
 <div class="container">
  <div class="layui-row layui-col-space10">
    <div class="layui-fluid">
      <fieldset class="layui-elem-field layui-field-title" id="yjfxk">
        <legend>示例</legend>
        <div class="layui-field-box">
          <div class="layui-row layui-col-space10" style="margin-top: 10px;">
            <div class="layui-col-lg4">
              <div style="height: 450px;overflow: auto;">
                <ul id="commonTree3" class="dtree" data-id="0"></ul>
                <input type="text" name="reportId5" id="reportId5" value="1" autocomplete="off" class="layui-input" readonly="">
              </div>
              <button id="btn">dsada</button>
            </div>
          </div>
        </div>
      </fieldset>
    </div>
  </div>
</div>

<script src="../layui/layui.js"></script>
<script>
  var data=[{
    "id":"1",
    "title": "湖南省",
    "isLast": false,
    "level": "1",
    "parentId": "0",
    "checkArr": [{"type": "0", "isChecked": "0"}],
    "children":[{
      "id":"001001",
      "title": "长沙市",
      "isLast":true,
      "parentId": "1",
      "checkArr": [{"type": "0", "isChecked": "0"}],
      "level": "2"
    },{
      "id":"001002",
      "title": "株洲市",
      "isLast":true,
      "parentId": "1",
      "checkArr": [{"type": "0", "isChecked": "0"}],
      "level": "2"
    },{
      "id":"001003",
      "title": "湘潭市",
      "isLast":true,
      "parentId": "1",
      "checkArr": [{"type": "0", "isChecked": "0"}],
      "level": "2"
    },{
      "id":"001004",
      "title": "衡阳市",
      "isLast":true,
      "parentId": "1",
      "checkArr": [{"type": "0", "isChecked": "0"}],
      "level": "2"
    },{
      "id":"001005",
      "title": "郴州市",
      "isLast":true,
      "parentId": "1",
      "checkArr": [{"type": "0", "isChecked": "0"}],
      "level": "2"
    }]
  }];

  layui.config({
  base: '../dtree/' //配置 layui 第三方扩展组件存放的基础目录
}).extend({
  dtree: 'dtree' //定义该组件模块名
}).use(['element','layer', 'dtree'], function(){
  var layer = layui.layer;
  var dtree = layui.dtree;
  var element = layui.element;
  var  $ = layui.$;

  dtree.render({
    elem: "#commonTree3",
    data:data,
    checkbar: true,  
    checkbarType: "no-all", // 默认就是all，其他的值为： no-all   p-casc   self
  });

  var reportId = $("#reportId5").val();
  console.log(reportId)
         dtree.chooseDataInit("commonTree3","1,001001"); // 初始化复选框的值
  // 点击按钮获取所有选中节点值
  $("#btn").click(function(){
    var params = dtree.getCheckbarNodesParam("commonTree3");
    var ids= [];
    var len=params.length;
    for (var i =0; i < len; i++) {
      ids.push(params[i].nodeId);
    }
    console.log(ids);

  });
});

</script>

</body>
</html>